******* Keeping Your Head Down Replication *********

clear
set more off
cap cd "/Users/paulschuler/Dropbox/Bo & NBT/JEAS Replication"


********************** Vietnam Tables and Figures ************************
use KeepHeadDown_VNdata

* Main VN Analysis Tables
probit  minister2011  ln_bm ln_bm2 
probit  minister2011  ln_bm ln_bm2 gdpConstantx  growth_rank 
probit  minister2011  ln_bm ln_bm2 gdpConstantx   risk_punish2 


reg  prom2  ln_bm ln_bm2, robust 
reg  prom2  ln_bm ln_bm2 gdpConstantx  growth_rank, robust
reg  prom2  ln_bm ln_bm2 gdpConstantx  risk_punish2, robust
reg  prom2  ln_bm ln_bm2 gdpConstantx  risk_punish2  if ln_bm>.5 & ln_bm<5, robust


* Generate Figure 4 - VN Panel
reg  prom2  ln_bm ln_bm2 gdpConstantx  risk_punish2, robust
predict p
gen dash = "|"
gen weight = -1.5
twoway (qfitci p ln_bm) (scatter  weight ln_bm, mlabel(dash) ms(none) title("With Extreme Values") xtitle("News Index") ///
ytitle("Promotion Index (-1 - 3)") legend(off))
graph save g1, replace
reg  prom2  ln_bm ln_bm2 gdpConstantx  risk_punish2  if ln_bm>.5 & ln_bm<5, robust
predict p2
twoway (qfitci p2 ln_bm if ln_bm>.5 & ln_bm<5) (scatter  weight ln_bm if ln_bm>.5 & ln_bm<5, mlabel(dash) ms(none) title("Without Extreme Values") xtitle("News Index") ///
ytitle("Promotion Index (-1 - 3)") legend(off))
graph save g2, replace
graph combine g1.gph g2.gph, ycommon


* Generate VN Descriptive Stats Table
gsort -bm_index
graph hbar bm_index, ytitle("News Stories (2007-2010)") over(name,  sort(bm_index) des lab(labsize(vsmall)))


********************** China Tables and Figures ************************

cap cd "/Users/ddgueorg/Dropbox/Bo & NBT/JEAS Replication"
use "China_18th.dta", replace

*** China Profiles, Figure 1 ***
graph hbar (mean) index2011 media2011, over(leader, sort(index2011) descending label(labsize(vsmall))) ///
stack legend(order(1 "Search Index" 2 "News Index") size(small) region(lcolor(none) lpattern(blank))) scheme(s1color)
graph save China_profiles.gph, replace


*** Bo Xilai Media Internet, Figure 2 ****
preserve
use "China_18th_bo_xilai.dta", clear
tset date
twoway (line pcindex date)(line mediaindex date), by(leader) xlabel(#3) xscale(range(18324 19790)) scheme(s1color)
restore

***Time in Office***
g time=2012-tenurebegin

***Merging in Survey Data***
merge m:m province using "China_18th_survey.dta", force
drop _merge

***Merging in Econ Data***
merge m:m province using "China_18th_growth.dta"
drop _merge

***Variable Transformation***
set more off
g ln_gdp=ln(gdp)
g ln_pop=ln(pop)
g ln_internet_pop=ln(internet_pop)
g ln_index=ln(index2011)
replace gdp_rank=32-gdp_rank
replace gdp_pc_rank=32-gdp_pc_rank
g ln_index_sq=ln_index^2
g ln_media = ln(media2011)
egen faction_id = group(faction)
replace faction_id=0 if faction_id==.
replace faction_id=0 if faction_id==3
drop rank 
g rank=0 
replace rank=1 if previous=="CC"
replace rank=2 if previous=="PB"
g promote_dum=0
replace promote_dum=1 if promoted>0

***Analysis 18th, Table 3***
probit promote_dum ln_index ln_index_sq 
outreg2 using china_table.xls, replace
probit promote_dum ln_index ln_index_sq gdp_rank 
outreg2 using china_table.xls, e(all)
probit promote_dum ln_index ln_index_sq gdp_rank i.faction_id
outreg2 using china_table.xls, e(all)
probit promote_dum ln_index ln_index_sq gdp_rank i.faction_id ln_internet ln_gdp gov_perf gov_obs
outreg2 using china_table.xls, e(all)

reg promoted ln_index ln_index_sq 
outreg2 using china_table.xls, e(all) 
reg promoted ln_index ln_index_sq gdp_rank
outreg2 using china_table.xls, e(all)
reg promoted ln_index ln_index_sq gdp_rank i.faction_id
outreg2 using china_table.xls, e(all)
reg promoted ln_index ln_index_sq gdp_rank i.faction_id ln_internet ln_gdp gov_perf gov_obs
outreg2 using china_table.xls, e(all)
reg promoted ln_index ln_index_sq gdp_rank i.faction_id ln_internet ln_gdp gov_perf gov_obs if leader!="Bo Xilai"
outreg2 using china_table.xls, e(all)

**For Replication (Without Profile)
probit promote_dum ln_index ln_index_sq gdp_rank i.faction_id ln_internet ln_gdp gov_perf gov_obs
probit promote_dum gdp_rank i.faction_id ln_internet ln_gdp gov_perf gov_obs
probit promote_dum gdp_rank i.faction_id ln_gdp 


*** China Curve, Figure 3 ***
reg promoted ln_index ln_index_sq gdp_rank i.faction_id ln_internet ln_gdp gov_perf gov_obs
predict p
gen dash = "|"
g spike=-3
twoway (qfitci p ln_index) (scatter  spike ln_index, mlabel(dash) ms(none) title("Full Sample") xtitle("Baidu Search Index (natural log)") ///
ytitle("Probability of Promotion") legend(off) )
graph save Graph "full_China_Curve.gph", replace

reg promoted ln_index ln_index_sq gdp_rank i.faction_id ln_internet ln_gdp gov_perf gov_obs if leader!="Bo Xilai"
outreg2 using china_table.xls, e(all)
predict b
twoway (qfitci b ln_index if leader!="Bo Xilai") (scatter  spike ln_index if leader!="Bo Xilai", mlabel(dash) ms(none) title("Without Bo Xilai") xtitle("Baidu Search Index (natural log)") ///
ytitle("Probability of Promotion") legend(off) )
graph save Graph "noBo_China_Curve.gph", replace
graph combine full_China_Curve.gph noBo_China_Curve.gph, ycommon
graph save Graph "China_curve_combined.gph", replace




********* CHINA PAST CONGRESSES (ROBUSTNESS) *********
clear
use "China_17th.dta", clear

g ln_gdp=ln(gdp_pc)
g ln_pop=ln(pop)
g ln_internet_pop=ln(pen)
g baidu1_sq=baidu1^2

***Data Cleaning, misaligned secretaries***

drop if sec_name=="Du Qinglin" & congress==2007
drop if sec_name=="Xi Jinping" & congress==2007 & province=="Shanghai"
drop if sec_name=="Wei Liucheng" & congress==2007
drop if sec_name=="Luo Qingquan" & congress==2007 & province=="Hubei"
replace sec_promote=0 if sec_name=="Wang Xiaofeng" & congress==2007

by congress, sort: egen gdp_rank=rank(change_gdp)

*** Analysis 17th and 16th, Table 5 ***

reg sec_promote baidu1 baidu1_sq if congress==2007
outreg2 using china_old.xls, e(all) replace 
reg sec_promote baidu1 baidu1_sq gdp_rank ln_gdp ln_internet_pop if congress==2007
outreg2 using china_old.xls, e(all) 

********* CHINA ALTERNATE CENTRAL COMMITTEE (ROBUSTNESS) *********

clear
set more off
use "China_18th_acc.dta", replace

ologit rank2 age career_age edu2 ethnic i.interest

predict rank3
egen rank4= rank(rank3)
sum rank4 

***
g b3=bm/4
g diff=b1-b3
g b2=b1^2
g bm2=bm^2
g diff2= diff^2
g ln_b1=ln(b1)
g ln_b1sq=ln_b1^2
g ln_bm=ln(bm)
g ln_bmsq=ln_bm^2
g ln_diff=ln(diff2)

*** Analysis ACC, Table 6 ***
set more off
bootstrap, reps(300) seed(1235) ties: poisson rank2 ln_b1 ln_b1sq  
outreg2 using china_acc_table.xls, e(all) replace 
bootstrap, reps(300) seed(1235) ties: poisson rank2 ln_b1 ln_b1sq age career_age edu2 ethnic i.interest
outreg2 using china_acc_table.xls, e(all)
bootstrap, reps(300) seed(1235): poisson rank4 ln_b1 ln_b1sq   
outreg2 using china_acc_table.xls, e(all)




****Combined China VN Graphics***
graph combine "China_profiles.gph" "Vietnam_profiles.gph" 
graph combine "China_curve_combined.gph" "Vietnam_curve_combined.gph", rows(2)
